/*
	Copyright (c) 2010 <copyright holders>
	This source code is licensed under The MIT License,
	see the file LICENSE for details.
	*/

#include <Ogre/Ogre.h>

#include "PresentationDefs.hpp"
#include "UglyDebug.hpp"

Ogre::SceneManager *UglyDebug::scnmgr_ = 0;
UglyDebug *UglyDebug::singleton_ = 0;

UglyDebug::UglyDebug()
{
    UglyDebug::scnmgr_ = Ogre::Root::getSingletonPtr()->getSceneManagerIterator().peekNextValue();
}
UglyDebug *UglyDebug::getSingleton()
{
    if(!singleton_) singleton_ = new UglyDebug();
    return singleton_;
}

void UglyDebug::addDebugMarker(float x, float y, float z, const char *model)
{
    Ogre::SceneNode *sceneNode = UglyDebug::scnmgr_->getRootSceneNode()->createChildSceneNode();
    Ogre::Entity *entity = UglyDebug::scnmgr_->createEntity(model);
	entity->setQueryFlags(spelprog2::presentation::ENTITY_QUERY_FLAG_OTHER);
    sceneNode->attachObject(entity);
    sceneNode->scale(1, 1, 1);

    sceneNode->setPosition(Ogre::Vector3(x, y, z));
    
    debugNodes.push_back(sceneNode);
}

void UglyDebug::clear()
{
    for(size_t i = 0; i < debugNodes.size(); i++)
    {
        scnmgr_->destroySceneNode(debugNodes[i]);
    }
    debugNodes.clear();
}